<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<% 
	String path = request.getContextPath(); 
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>新增项目</title>
	<base href="<%=basePath%>" />
	<%@ include file="../../cuv_include.jsp"%>
	<style type="text/css"> 
  		fieldset,legend,form,table,tr,td{margin:0;padding:0}
  		form label {font-weight:bold;}
  		table{margin:10px 10px};
  		td{line-height: 40px;}
  		input[type="text"]{width:250px;}
  		input[type="password"]{width:250px;}
  		input[type="textarea"]{width:250px;}
	</style>
	<script type="text/javascript">
		//返回列表页面
	    function btn_return(){
	    	window.location.href="<%=basePath%>soft/project/list.do";
	    }
	   
	    $(document).ready(function(){
	    	$("#name").focus();
	        var options = {dataType: 'json', beforeSubmit: beforeSubmit, success: process};
	        $("#projectForm").submit(function(){
	            $(this).ajaxSubmit(options);
	            return false;
	        });      
	    });
	    
	    function getPerson()
	    {
	    	var deptNo=$("#alldept").val();
			$.ajax({
			  type:"post",
			  url:"<%=basePath%>/system/user/getUserByDeptNo.do", 
			  data:'deptNo='+deptNo,
			  timeout:20000,
			  error:function() {
			      alert('服务器错误');
			    },
		      async:false,
			  success:function(data) {
				  	 var m=eval(data);                 //转换 成json对象
					 $("#projectManager").empty();  //清空内容 
					 $("#projectManager").prepend("<option value='' selected='selected'>请选择</option>");   //为Select插入一个Option(第一个位置) 
					 $.each(m, function(i) {  
					    $('#projectManager').append('<option value="'+m[i].enname+'">' + m[i].cnname+ '</option>');   
				     });
			    }
		    });
	    }
	    
	    function beforeSubmit() {
	        if(isEmpty($.trim($("#name").val()))){
		  		alert("项目名称不能为空！");
		  		$("#name").focus();
		  		return false;
	  		}
	  		if(!validateSize( $("#name").val(),2,15)){
		  		alert("项目名称不符合规格！");
		  		$("#name").focus();
          		return false;
	  		}
	  		if(isEmpty($.trim($("#version").val()))){
		  		alert("项目版本不能为空！");
		  		$("#version").focus();
		  		return false;
	  		}
	  		if(isEmpty($("#alldept").val())){
		  		alert("所属部门不能为空！");
		  		$("#projectManager").focus();
		  		return false;
	  		}
	  		if(isEmpty($("#projectManager").val())){
		  		alert("项目经理不能为空！");
		  		$("#projectManager").focus();
		  		return false;
	  		}
	  		if(isEmpty($.trim($("#consumer").val()))){
		  		alert("客户不能为空！");
		  		$("#consumer").focus();
		  		return false;
	  		}
	  		if(isEmpty($("#status").val())){
		  		alert("请选择状态！");
		  		$("#status").focus();
		  		return false;
	  		}

	        return true;
	    }
        function process(responseJson) {
	        if(responseJson.code == 0) {
	            $('#error_label').text("错误信息：" + responseJson.message);
	            $("#p_error").show();
	            return;
	        }
	        var qs = $("#qs").val();
	        location.href = "<%=basePath%>soft/project/list.do?" + qs;
        }  
	</script>
</head>
<body>
  <div>
    <fieldset>
      <legend>新增项目：</legend>
      <form id="projectForm" method="post" action="soft/project/insert.do">
	      <input id="qs" name="qs" type="hidden" value="${qs}"/>
	     	<p id = "p_error" style = "margin:10px 10px;">
	     	    <label id="error_label" style="color:red;"></label>
	     	</p>
	        <table>
		          <tr>
			            <td><label for="name">项目名称：</label></td>
			            <td>
			            	<input type="text" name="name" id="name" />
			            	<font color="red">&nbsp;*&nbsp;&nbsp;</font>
			            </td>
		          </tr>
		          <tr>
			            <td><label for="version">项目版本：</label></td>
			            <td>
			            	<input type="text" name="version" id="version" />
			            	<font color="red">&nbsp;*&nbsp;&nbsp;</font>
			            </td>
		          </tr>
		          
		          
		           <tr>
		             <td><label for="dept">部门：</label></td>
		              <td >
		               <select id="alldept"  onChange="getPerson();">
		                    <option value="">-- 选择项目经理所在部门--</option>
							<c:forEach var="dept1" items="${allDeptList}">
								<option  value="${dept1.deptNo}">${dept1.deptName}</option>
							</c:forEach>
				    	</select>
				    	 <font color="red">&nbsp;*&nbsp;&nbsp;</font> 
		            </td>              
		          </tr>   
		          
		          <tr>
			            <td><label for="projectManager">项目经理：</label></td>
			            <td>
			                <select id="projectManager" name="projectManager" >
					    	</select>
			               <font color="red">&nbsp;*&nbsp;&nbsp;</font> 
			            </td>
		          </tr>
		                 
		         
		          <tr>
			            <td><label for="consumer">客户：</label></td>
			            <td>
			            	<input type="text" name="consumer" id="consumer" />
			            	<font color="red">&nbsp;*&nbsp;&nbsp;</font>
			            </td>
		          </tr>
		          <tr>
			            <td><label for="status">使用状态：</label></td>
			            <td>
			            	<select name="status" id="status">
				                <c:forEach items="${dictItemList}" var="dict1">
		                            <option value="${dict1.value}">${dict1.name}</option>
		                        </c:forEach>
			               </select>
			               <font color="red">&nbsp;*&nbsp;&nbsp;</font> 
			            </td>
		          </tr>
		          <tr>
			            <td valign="top"><label for="description">描述：</label></td>
			            <td valign="top"><textarea name="description" id="description" cols="40" rows="3"></textarea></td>
		          </tr>                   
		          <tr>
			            <td></td>
			            <td>
			            	<input type="submit" id="btn_insert" value="提交" style="width:80px;" />
			            	<input type="button" id="btn_back" value="返回" onclick="btn_return();" style="width:80px;" />
			            </td>
		          </tr>
	        </table>
      </form>
    </fieldset>
  </div>
</body>
</html>